package com.tinyseed.emcp.api.basicdata.domain;

import com.tinyseed.emcp.api.basicdata.domain.convert.DTOConvert;
import com.tinyseed.emcp.api.basicdata.model.MonitorOutputDTO;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.hibernate.annotations.GenericGenerator;
import org.springframework.beans.BeanUtils;

import javax.persistence.*;
import java.io.Serializable;
import java.sql.Timestamp;

/***
 * @ClassName: Monitor
 * @Description: 监测点信息实体类
 * @Auther: Harlan.Xiong
 * @Date: 2019-11-23 19:42
 * @version : V1.0
 */
@Data
@Table(name = "tb_monitor")
@Entity()
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class Monitor implements Serializable {
    /**
     * 唯一主键
     */
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO	, generator = "myid")
    @GenericGenerator(name = "myid", strategy = "com.tinyseed.emcp.api.app.common.ManulInsertGenerator")
    private Long id;

    /**
     * 监测点名字
     */
    @Column(nullable = true)
    private String monitorName;

    /**
     * 网关编号
     */
    @Column(nullable = true)
    private String switchSn;

    /**
     * 功率启停阈值(kW)
     */
    @Column(nullable = true)
    private Float powerLimit;

    /**
     * 功率门限时间(分钟)
     */
    @Column(nullable = true)
    private Long powerTime;

    /**
     * 车间id
     */
    @Column(nullable = true)
    private Long shopId;

    /**
     * 电压变比(电压互感器)
     */
    @Column(nullable = true)
    private String pt;

    /**
     * 电流变比(电流互感器)
     */
    @Column(nullable = true)
    private String ct;

    /**
     * 备注
     */
    @Column(nullable = true)
    private String remark;

    /**
     * 创建时间
     */
    @Column(nullable = true)
    private Timestamp createTime;
    /**
     * 最后修改时间
     */
    @Column(nullable = true)
    private Timestamp modifyTime;
    /**
     * 创建人
     */
    @Column(nullable = true)
    private String creator;
    /**
     * 最后操作人
     */
    @Column(nullable = true)
    private String modifier;

    /**
     * 监测点编码
     */
    @Column(nullable = true)
    private String monitorCode;

    /**
     * 设备类型
     */
    @Column(nullable = true)
    private String equipmentType;

    /**
     * 仪表地址
     */
    @Column(nullable = true)
    private String instrumentAddress;

    /**
     * 仪表型号
     */
    @Column(nullable = true)
    private String instrumentModel;

    /**
     * 额定功率(kw)
     */
    @Column(nullable = true)
    private Float ratedPower;

    /**
     * 额定电压(V)
     */
    @Column(nullable = true)
    private Float ratedVoltage;

    @ManyToOne(optional = true, fetch = FetchType.LAZY)
    @JoinColumn(name = "shopId", referencedColumnName = "id", insertable = false, updatable = false)
    private Workshop workshop;

    public MonitorOutputDTO convertToMonitorOutputDTO() {
        Monitor.MonitorOutputDTOConvert convert = new Monitor.MonitorOutputDTOConvert();
        return convert.convert(this);
    }

    private static class MonitorOutputDTOConvert implements DTOConvert<Monitor, MonitorOutputDTO> {

        @Override
        public MonitorOutputDTO convert(Monitor monitor) {
            MonitorOutputDTO monitorOutputDTO = new MonitorOutputDTO();
            BeanUtils.copyProperties(monitor, monitorOutputDTO);
            return monitorOutputDTO;
        }
    }
}
